// ignore_for_file: must_be_immutable, prefer_typing_uninitialized_variables

import 'package:aitao_flutter/common_ui/age_widget.dart';
import 'package:aitao_flutter/common_ui/online_status.dart';
import 'package:aitao_flutter/res/r.dart';
import 'package:aitao_flutter/style/color_style.dart';
import 'package:aitao_flutter/style/radius_style.dart';
import 'package:aitao_flutter/style/text_style.dart';
import 'package:aitao_flutter/utils/common_utils.dart';
import 'package:aitao_flutter/utils/sp_utils.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import '../../model/home_item_model.dart';

class HomeItemWidget extends StatelessWidget {
  HomeItemWidget(
      {Key? key, required this.model, required this.itemClickCallBack})
      : super(key: key);
  HomeItemModel model;
  var itemClickCallBack;
  @override
  Widget build(BuildContext context) {
    // debugPrint('HomeItemWidget build');
    return GestureDetector(
      child: Container(
          decoration: const BoxDecoration(
              // borderRadius: RadiusStyle.radiusAll(8),
              color: ColorStyle.whiteColor),
          child: ClipRRect(
            borderRadius: RadiusStyle.radiusAll(8),
            child: Stack(children: [
              Positioned(
                  top: 0,
                  left: 0,
                  right: 0,
                  bottom: 0,
                  child: CommonUtils.isImageSuffix(model.avatar ?? '')
                      ? CachedNetworkImage(
                          fit: BoxFit.fill,
                          imageUrl: SpUtil.getImageUrl(model.avatar ?? ''),
                          placeholder: (context, str) {
                            return Image.asset(model.gender == 1
                                ? ImagePath.assetsImagesHeaderForWomen
                                : ImagePath.assetsImagesHeaderForMan);
                          },
                          errorWidget: (context, str, obj) {
                            return Image.asset(model.gender == 1
                                ? ImagePath.assetsImagesHeaderForWomen
                                : ImagePath.assetsImagesHeaderForMan);
                          },
                        )
                      : Container(
                          color: ColorStyle.whiteColor,
                          child: Image.asset(
                            model.gender == 1
                                ? ImagePath.assetsImagesHeaderForWomen
                                : ImagePath.assetsImagesHeaderForMan,
                          ))),
              Positioned(
                  top: 8,
                  right: 8,
                  child: Row(
                    children: [
                      Visibility(
                          visible: model.vip != 2,
                          child: Image.asset(CommonUtils.setVipImagePath(
                              model.vip ?? 2, model.vipLevel ?? 1))),
                      Text(
                        model.nickname ?? '',
                        style: Styles.whiteText_13,
                      )
                    ],
                  )),
              Positioned(
                  bottom: 8,
                  left: 10,
                  right: 10,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      AgeWidget(
                        age: model.age ?? 1,
                        gender: model.gender ?? 1,
                      ),
                      OnlineStatus(status: model.userState ?? 1)
                    ],
                  ))
            ]),
          )),
      onTap: () {
        itemClickCallBack(model);
      },
    );
  }
}
